در این پروژه رخدادهای امنیت پروازها از سال ۱۹۱۹ تا کنون را بررسی می کنیم.
توضیحات نحوه ی جمع آوری داده ها و پاکسازی آن در فایل report.pdf آمده است. همچنین در فاز پیشین تحلیل مکاشفه ای بر روی داده ها صورت گرفته و به سوالات ۱ و ۶ و ۷ پاسخ داده شده بود.
داده های ذخیره شده از طریق لینک زیر قابل دسترسی است:
https://github.com/Ajal88/DA_Project
کتابخانه های مورد نیاز و بارگذاری داده ها
library(readr)
library(dplyr)
library(stringr)
library(highcharter)
library(ggplot2)
library(stringr)
library(topicmodels)
library(tidytext)
casn <- readr::read_csv("Data/asn_c.csv") %>% as.data.frame(stringsAsFactors = F) %>%
mutate(Total_occupants = ifelse(Total_occupants == 0 & Total_fatalities != 0, Total_fatalities, Total_occupants),
Total_survivors = abs(Total_occupants - Total_fatalities)) %>%
mutate(Total_survivors = ifelse(Total_survivors > Total_occupants, Total_occupants, abs(Total_occupants - Total_fatalities))) %>%
mutate(is_army = str_detect(Operator, regex("Force|Navy",ignore_case = T))) %>%
mutate(occ_no = row_number())۱. آنالیز متن و دسته بندی علت وقوع مشکلات پرواز ها
برای این منظور می خواهیم از مدل lda استفاده کنیم. به همین دلیل ابتدا از داده های اصلی تنها شماره ی تصادف و Narrative را انتخاب می کنیم. سپس علت سقوط را به کلمات آن تبدیل می کنیم و stopwords را از آن حذف می کنیم. سپس کلمات رایج در سقوط هواپیما همچون هواپیما و پرواز را از کلمات حذف می کنیم. در نهایت نیز تعداد تکرار هر لغت را برای هر Narrative بدست می آوریم. سپس از آنجایی که LDA با DocumentTermMatrix کار می کند، ساختار داده ی خود را به این صورت تغییر می دهیم. در نهایت نیز مدل خود را با ۲۰ topic لرن می کنیم. از آنجایی که لرن مدل وقت گیر است، مدل را برای استفاده ی آینده ذخیره می کنیم.
cause <- casn %>% select(occ_no, Narrative)
# split into words
cause_word <- cause %>%
unnest_tokens(output = word, input = Narrative)
# plane stopwords
word = c("aircraft", "airplane", "plane", "flight")
plane_stop_words = data_frame(word)
word_counts <- cause_word %>%
anti_join(stop_words) %>%
anti_join(plane_stop_words) %>%
count(occ_no, word, sort = TRUE)
flight_dtm <- word_counts %>%
cast_dtm(occ_no, word, n)accident_lda <- LDA(flight_dtm, k = 20, control = list(seed = 1234))
saveRDS(accident_lda, file="Data/lda.rds")accident_lda = readRDS(file="Data/lda.rds")سپس برای هر topic پنج کلمه ای که بیشترین احتمال حضور در این موضوع دارد را نمایش می دهیم.
accident_topics <- tidy(accident_lda, matrix = "beta")
top_terms <- accident_topics %>%
group_by(topic) %>%
top_n(5, beta) %>%
ungroup() %>%
arrange(topic, -beta)
top_terms %>%
mutate(term = reorder(term, beta)) %>%
ggplot(aes(term, beta, fill = factor(topic))) +
geom_col(show.legend = FALSE) +
facet_wrap(~ topic, scales = "free", nrow = 5) +
coord_flip()top_terms_merge <- top_terms %>% group_by(topic) %>% summarise(words = paste(term, collapse=", "))
knitr::kable(top_terms_merge)| topic | words |
|---|---|
| 1 | landing, gear, main, collapsed, undercarriage |
| 2 | sea, missing, water, hit, hangar |
| 3 | runway, feet, short, left, rest |
| 4 | crash, terrain, lake, airstrip, pilot |
| 5 | engine, fuel, wing, left, takeoff |
| 6 | pilot, crew, test, cabin, system |
| 7 | hijacker, demanded, hijackers, passengers, 1 |
| 8 | runway, captain, feet, approach, pilot |
| 9 | damage, airport, sustained, substantial, accident |
| 10 | crashed, mountain, 2, km, antonov |
| 11 | accident, destroyed, killed, airport, crew |
| 12 | fire, caught, ground, destroyed, de |
| 13 | feet, departed, crew, reported, cleared |
| 14 | engine, takeoff, landing, forced, lost |
| 15 | damaged, repair, accident, reportedly, raf |
| 16 | airport, boeing, international, air, otter |
| 17 | dc, 3, struck, 4, douglas |
| 18 | en, route, night, operation, NA |
| 19 | air, force, transport, base, flying |
| 20 | approach, weather, pilot, conditions, visibility |
۲. رتبه بندی علت وقوع مشکلات برای پرواز ها
برای این بخش احتمال هر تاپیک برای هر سند را بدست می آوریم. (gamma) سپس تاپیکی که بیشترین احتمال را داراست به عنوان موضوع سند انتخاب می کنیم. سپس پروازها را بر اساس تاپیک دسته بندی کردی و تعداد رخدادهای امنیتی هر تاپیک را بدست می آوریم. نمودار علت سقوط پروازها بر اساس تعداد تکرار به صورت زیر است:
accidents_gamma <- tidy(accident_lda, matrix = "gamma")
accidents_data <- accidents_gamma %>% group_by(document) %>%
top_n(1, gamma) %>%
ungroup()
accident_summary <- accidents_data %>% group_by(topic) %>% summarise(count = n()) %>%
arrange(desc(count))
accident_summary <- accident_summary %>% inner_join(top_terms_merge, by = c("topic"))
occurance_sum = sum(accident_summary$count)
accident_summary <- accident_summary %>% mutate(count_percent = 100*count/occurance_sum)
knitr::kable(accident_summary %>% select(-count_percent))| topic | count | words |
|---|---|---|
| 10 | 2169 | crashed, mountain, 2, km, antonov |
| 15 | 1816 | damaged, repair, accident, reportedly, raf |
| 14 | 1672 | engine, takeoff, landing, forced, lost |
| 19 | 1296 | air, force, transport, base, flying |
| 9 | 1212 | damage, airport, sustained, substantial, accident |
| 7 | 1206 | hijacker, demanded, hijackers, passengers, 1 |
| 3 | 1184 | runway, feet, short, left, rest |
| 11 | 1122 | accident, destroyed, killed, airport, crew |
| 20 | 1024 | approach, weather, pilot, conditions, visibility |
| 2 | 986 | sea, missing, water, hit, hangar |
| 18 | 893 | en, route, night, operation, NA |
| 1 | 875 | landing, gear, main, collapsed, undercarriage |
| 13 | 862 | feet, departed, crew, reported, cleared |
| 12 | 741 | fire, caught, ground, destroyed, de |
| 5 | 673 | engine, fuel, wing, left, takeoff |
| 8 | 667 | runway, captain, feet, approach, pilot |
| 6 | 640 | pilot, crew, test, cabin, system |
| 4 | 636 | crash, terrain, lake, airstrip, pilot |
| 17 | 633 | dc, 3, struck, 4, douglas |
| 16 | 570 | airport, boeing, international, air, otter |
accident_summary %>% arrange(topic) %>%
hchart(type = "pie", hcaes(x = words ,y = count_percent)) %>%
hc_yAxis(title = list(text = "Count")) %>%
hc_xAxis(title = list(text = "Topic")) %>%
hc_title(text = "Airsafety Occurance Based on Topic", style = list(fontWeight = "bold")) %>%
hc_add_theme(hc_theme_538())۳. آیا در صورت سقوط پرواز یک ایرلاین، دیگر نباید با آن پرواز کنیم؟
۴. آیا واقعا سن هواپیما در سقوط آن موثر است؟
۵. چه ویژگی هایی از ایرلاین در رخدادهای امنیتی آن تاثیر دارد؟(نظیر قدمت، کشور و …)
۶. بدترین خطوط هوایی، بدترین پروازها، بدترین هواپیماها
بدترین خطوط هوایی، بدترین هواپیماها و بدترین فرودگاه ها
ابتدا معیار بد بودن را انتخاب می کنیم، از آنجایی که شرکت هایی که تعداد پایینی پرواز و یا پروازهای کوچکی داشته باشند، در صورت سقوط دارای نرخ پایین زنده ماندن هستند اما در واقع حادثه بزرگی به شمار نمی آیند، تنها خطوط هوایی، هواپیماها و فرودگاه هایی را انتخاب می کنیم که بالای ۵۰۰ نفر مسافر داشته اند. سپس معیار بد بودن را نرخ پایین زنده ماندن در نظر میگیریم.
# worst airline
worst_airline <- casn %>% filter(!is.na(Operator)) %>%
filter(is_army == FALSE) %>%
group_by(Operator) %>%
summarise(Total_occupants = sum(Total_occupants), Total_fatalities = sum(Total_fatalities),
Total_survivors = sum(Total_survivors), Survival_rate = 100*Total_survivors/Total_occupants) %>%
ungroup() %>%
filter(Total_occupants > 500) %>%
top_n(20, wt = desc(Survival_rate)) %>%
arrange(Survival_rate)
p = ggplot(data = worst_airline, mapping = aes(x = reorder(Operator, Survival_rate), y = Survival_rate, fill = Total_fatalities)) +
geom_bar(stat="identity") + scale_fill_gradient(low="brown1", high="brown4") +
ggtitle("Worst Airlines with lowest survival rate") +
xlab("Airline") +
ylab("Survival rate") + guides(color=guide_legend(title="fatality"), fill=guide_legend(title="fatality")) +
coord_flip()
p# worst airplane
worst_airplane <- casn %>% filter(!is.na(Type)) %>%
filter(is_army == FALSE) %>%
group_by(Type) %>%
summarise(Total_occupants = sum(Total_occupants), Total_fatalities = sum(Total_fatalities),
Total_survivors = sum(Total_survivors), Survival_rate = 100*Total_survivors/Total_occupants) %>%
ungroup() %>%
filter(Total_occupants > 500) %>%
top_n(20, wt = desc(Survival_rate)) %>%
arrange(Survival_rate)
p = ggplot(data = worst_airplane, mapping = aes(x = reorder(Type, Survival_rate), y = Survival_rate, fill = Total_fatalities)) +
geom_bar(stat="identity") +
ggtitle("Worst Airplanes with lowest survival rate") +
xlab("Airplane") +
ylab("Survival rate") + guides(color=guide_legend(title="fatality"), fill=guide_legend(title="fatality")) +
coord_flip()
p# worst route
worst_departure_airport <- casn %>% filter(!is.na(DepartureAirport)) %>%
filter(is_army == FALSE) %>%
group_by(DepartureAirport) %>%
summarise(Total_occupants = sum(Total_occupants), Total_fatalities = sum(Total_fatalities),
Total_survivors = sum(Total_survivors), Survival_rate = 100*Total_survivors/Total_occupants) %>%
ungroup() %>%
filter(Total_occupants > 500) %>%
top_n(20, wt = desc(Survival_rate)) %>%
arrange(Survival_rate)
p = ggplot(data = worst_departure_airport, mapping = aes(x = reorder(DepartureAirport, Survival_rate), y = Survival_rate, fill = Total_fatalities)) +
geom_bar(stat="identity") + scale_fill_gradient(low="midnightblue", high="darkred") +
ggtitle("Worst Departure Airports with lowest survival rate") +
xlab("Departure Airport") +
ylab("Survival rate") + guides(color=guide_legend(title="fatality"), fill=guide_legend(title="fatality")) +
coord_flip()
p۷. سالانه چندین تصادف هوایی رخ می دهد؟ چند نفر سوار پرواز بوده اند؟ چند نفر جان سالم به در برده و چند نفر فوت کرده است؟
بررسی روند تلفات رخدادهای امنیتی پروازها در طول سالیان
برای این منظور ابتدا داده ها را بر اساس سال گروه بندی می کنیم، سپس تعداد تلفات، بازماندگان، افراد درگیر در حادثه و نرخ زنده ماندن را بدست می آوریم.(برای سال ۱۹۲۱ داده ی مناسبی به وجود نداشت به همین علت این سال از داده ها حذف شده است.)
# army and civil flights
year_fat <- casn %>% filter(!is.na(Date)) %>% group_by(Date) %>%
summarise(Total_occupants = sum(Total_occupants), Total_fatalities = sum(Total_fatalities),
Total_survivors = sum(Total_survivors), Survival_rate = 100*Total_survivors/Total_occupants)
# remove bad data
year_fat <- year_fat[-c(3),]
highchart() %>%
hc_add_series(data = year_fat, type = "spline", hcaes(x = Date, y = Total_fatalities), name = "Total Fatalities") %>%
hc_add_series(data = year_fat, type = "spline", hcaes(x = Date, y = Total_survivors), name = "Total Survivors") %>%
hc_yAxis(title = list(text = "Count")) %>%
hc_xAxis(title = list(text = "Year")) %>%
hc_title(text = "Fatalities Per Year", style = list(fontWeight = "bold")) %>%
hc_add_theme(hc_theme_flat())همانطور که مشاهده می کنیم، تلفات حوادث در حال کاهش است. البته باید دقت داشته باشیم که این کاهش هم چنین نشانگر این است که استاندارد پرواز ها بالاتر رفته است. زیرا هر چه سال جلوتر می روند، تکنولوژی نیز پیشرفت کرده و تعداد مسافران هواپیماها افزایش یافته و استفاده از سفر هوایی بیشتر می شود. پس تعداد مسافرین بیشتر شده و تعداد کشتگان کمتر می شود که نشان دهنده ی بهبود وضعیت است.
year_fat %>%
hchart(type = "spline", hcaes(x = Date, y = Survival_rate), name = "Survival Rate") %>%
hc_yAxis(title = list(text = "Survival Rate")) %>%
hc_xAxis(title = list(text = "Year")) %>%
hc_title(text = "Survival Rate Per Year", style = list(fontWeight = "bold")) %>%
hc_add_theme(hc_theme_sandsignika())با توجه به نمودارهای بالا همانطور که انتظار داشتیم، نرخ زنده ماندن تقریبا به صورت خطی بیشتر شده است.
۸. در هر کدام از دسته های علت وقوع مشکلات پروازها، چه هواپیماهایی دچار مشکل شدند و چند کشته برجای گذاشته اند؟
۹. آیا وقوع رخدادهایی برای یک ایرلاین باعث بهبود روند آن می شود؟
۱۰. انتخاب ارزان ترین پروازها، به معنی ناامن بودن آنها است؟
۱۱. اضافه کردن معیار امنیت به پروازها
۱۲. رده بندی پروازها بر اساس امنیت
۱۳. تاثیر وقوع سانحه ی هوایی بر روی قیمت بلیت های آن ایرلاین
۱۴. تاثیر تحریم ها بر روی سوانح هوایی ایران و تحلیل سوالات فوق برای ایران